/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkl51.controller;

import java.util.logging.Level;
import java.util.logging.Logger;
import pkl51.error.EntityException;
import pkl51.model.Blok5Model;
import pkl51.view.kuesioner.PanelBlok5;

/**
 *
 * @author ERI
 */
public class Blok5Controller {

    private Blok5Model model;

    public void setModel(Blok5Model model) {
        this.model = model;
    }

    public void insertBlok5(PanelBlok5 panelBlok5) throws EntityException {
        String B5R1a = panelBlok5.getTextFieldB5R1a().getText();
        String B5R1b = panelBlok5.getTextFieldB5R1b().getText();
        String B5R1c = panelBlok5.getTextFieldB5R1c().getText();
        String B5R2ia = panelBlok5.getTextFieldB5R2ia().getText(); 
        String B5R2ib = panelBlok5.getTextFieldB5R2ib().getText();
        String B5R2ic = panelBlok5.getTextFieldB5R2ic().getText();
        String B5R2id = panelBlok5.getTextFieldB5R2id().getText();
        String B5R2iia = panelBlok5.getTextFieldB5R2iia().getText();
        String B5R2iib = panelBlok5.getTextFieldB5R2iib().getText();
        String B5R2iic = panelBlok5.getTextFieldB5R2iic().getText();
        String B5R2iid = panelBlok5.getTextFieldB5R2iid().getText();
        String B5R2iie = panelBlok5.getTextFieldB5R2iie().getText();
        String B5R2iif = panelBlok5.getTextFieldB5R2iif().getText();
        String B5R2iig = panelBlok5.getTextFieldB5R2iig().getText();
        String B5R2iih = panelBlok5.getTextFieldB5R2iih().getText();
        String B5R2iiia = panelBlok5.getTextFieldB5R2iiia().getText();
        String B5R2iiib = panelBlok5.getTextFieldB5R2iiib().getText();
        String B5R2iiic = panelBlok5.getTextFieldB5R2iiic().getText();

        model.setForDB(B5R1a, B5R1b, B5R1c, B5R2ia, B5R2ib, B5R2ic, B5R2id, B5R2iia, B5R2iib, B5R2iic, B5R2iid, B5R2iie, B5R2iif, B5R2iig, B5R2iih, B5R2iiia, B5R2iiib, B5R2iiic);
        try {
            model.insertBlok5();
        } catch (EntityException ex) {
            Logger.getLogger(Blok5Controller.class.getName()).log(Level.SEVERE, null, ex);
            throw new EntityException("Insert data blok 5 gagal");
        }
    }

    public void updateBlok5(PanelBlok5 panelBlok5) throws EntityException {

        String B5R1a = panelBlok5.getTextFieldB5R1a().getText();
        String B5R1b = panelBlok5.getTextFieldB5R1b().getText();
        String B5R1c = panelBlok5.getTextFieldB5R1c().getText();
        String B5R2ia = panelBlok5.getTextFieldB5R2ia().getText(); 
        String B5R2ib = panelBlok5.getTextFieldB5R2ib().getText();
        String B5R2ic = panelBlok5.getTextFieldB5R2ic().getText();
        String B5R2id = panelBlok5.getTextFieldB5R2id().getText();
        String B5R2iia = panelBlok5.getTextFieldB5R2iia().getText();
        String B5R2iib = panelBlok5.getTextFieldB5R2iib().getText();
        String B5R2iic = panelBlok5.getTextFieldB5R2iic().getText();
        String B5R2iid = panelBlok5.getTextFieldB5R2iid().getText();
        String B5R2iie = panelBlok5.getTextFieldB5R2iie().getText();
        String B5R2iif = panelBlok5.getTextFieldB5R2iif().getText();
        String B5R2iig = panelBlok5.getTextFieldB5R2iig().getText();
        String B5R2iih = panelBlok5.getTextFieldB5R2iih().getText();
        String B5R2iiia = panelBlok5.getTextFieldB5R2iiia().getText();
        String B5R2iiib = panelBlok5.getTextFieldB5R2iiib().getText();
        String B5R2iiic = panelBlok5.getTextFieldB5R2iiic().getText();

        model.setForDB(B5R1a, B5R1b, B5R1c, B5R2ia, B5R2ib, B5R2ic, B5R2id, B5R2iia, B5R2iib, B5R2iic, B5R2iid, B5R2iie, B5R2iif, B5R2iig, B5R2iih, B5R2iiia, B5R2iiib, B5R2iiic);
        try {
            model.updateBlok5();
        } catch (EntityException ex) {
            Logger.getLogger(Blok5Controller.class.getName()).log(Level.SEVERE, null, ex);
            throw new EntityException("Update data blok 5 gagal");
        }

    }

    public void getBlok5ByNKS(PanelBlok5 panelBlok5) throws EntityException {
        try {
            model.getBlok5ByNks();
            
            panelBlok5.getTextFieldB5R1a().setText(model.getB5R1a());
            panelBlok5.getValidasiBlok5().setB5R1a(Integer.parseInt(model.getB5R1a()));
            
            panelBlok5.getTextFieldB5R1b().setText(model.getB5R1b());
            panelBlok5.getValidasiBlok5().setB5R1a(Integer.parseInt(model.getB5R1b()));
            
            panelBlok5.getTextFieldB5R1c().setText(model.getB5R1c());
            panelBlok5.getValidasiBlok5().setB5R1a(Integer.parseInt(model.getB5R1c()));
            
            panelBlok5.getTextFieldB5R2ia().setText(model.getB5R2ia());
            panelBlok5.getTextFieldB5R2ib().setText(model.getB5R2ib());
            panelBlok5.getTextFieldB5R2ic().setText(model.getB5R2ic());
            panelBlok5.getTextFieldB5R2id().setText(model.getB5R2id());
            panelBlok5.getTextFieldB5R2iia().setText(model.getB5R2iia());
            panelBlok5.getTextFieldB5R2iib().setText(model.getB5R2iib());
            panelBlok5.getTextFieldB5R2iic().setText(model.getB5R2iic());
            panelBlok5.getTextFieldB5R2iid().setText(model.getB5R2iid());
            panelBlok5.getTextFieldB5R2iie().setText(model.getB5R2iie());
            panelBlok5.getTextFieldB5R2iif().setText(model.getB5R2iif());
            panelBlok5.getTextFieldB5R2iig().setText(model.getB5R2iig());
            panelBlok5.getTextFieldB5R2iih().setText(model.getB5R2iih());
            panelBlok5.getTextFieldB5R2iiia().setText(model.getB5R2iiia());
            panelBlok5.getTextFieldB5R2iiib().setText(model.getB5R2iiib());
            panelBlok5.getTextFieldB5R2iiic().setText(model.getB5R2iiic());
            
            
            
            
        } catch (EntityException e) {
            throw new EntityException("Data blok5 tidak ditemukan");
        }

    }
}